local skel = fk.CreateSkill {
  name = "rmt__jiangbing",
  dynamic_desc = function (self, player, lang)
    if player:getMark("rmt__jiangbing_limit") ~= 0 then
      return "rmt__jiangbing_limit"
    end
  end,
}

Fk:loadTranslationTable{
  ["rmt__jiangbing"] = "将柄",
  [":rmt__jiangbing"] = "出牌阶段，你可以视为使用【借刀杀人】，场上牌数因此改变后，此技能标签增加“限定技”。",
  -- 注意，刚增加限定技标签时，仍可使用一次

  [":rmt__jiangbing_limit"] = "限定技，出牌阶段，你可以视为使用【借刀杀人】。",

  ["rmt__jiangbing_limit"] = "将柄-限定",
  ["#rmt__jiangbing"] = "将柄：视为使用【借刀杀人】",

  ["$rmt__jiangbing1"] = "众士齐言，元氏灭，尔朱兴！",
  ["$rmt__jiangbing2"] = "戒勒士马，校猎嵩原。六合宁一，八表无尘。",
}

skel:addEffect("viewas", {
  mute = true,
  pattern = "collateral",
  prompt = "#rmt__jiangbing",
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local c = Fk:cloneCard("collateral")
    c.skillName = skel.name
    return c
  end,
  before_use = function(self, player, use)
    player:broadcastSkillInvoke(skel.name)
    player.room:notifySkillInvoked(player, skel.name, player:getMark("rmt__jiangbing_limit") == 0 and "control" or "big")
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryGame) == 0 or player:getMark("rmt__jiangbing_limit") == 0
  end,
  enabled_at_response = Util.FalseFunc,
})

skel:addEffect(fk.AfterCardsMove, {
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(skel.name, true) and player:getMark("rmt__jiangbing_limit") == 0 then
      if table.find(data, function(move) return
        table.find(move.moveInfo, function(info)
          return info.fromArea == Card.PlayerEquip or info.fromArea == Card.PlayerJudge
        end) ~= nil
      end) then
        local e = player.room.logic:getCurrentEvent()
        if e.parent and e.parent.parent then
          e = e.parent.parent
          if e.event == GameEvent.CardEffect then
            local effect = e.data
            return table.contains(effect.card.skillNames, skel.name)
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player:setSkillUseHistory(skel.name, 0, Player.HistoryGame)
    player.room:setPlayerMark(player, "rmt__jiangbing_limit", 1)
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "rmt__jiangbing_limit", 0)
  player:setSkillUseHistory(skel.name, 0, Player.HistoryGame)
end)

skel:addAcquireEffect(function (self, player, is_start)
  player.room:setPlayerMark(player, "rmt__jiangbing_limit", 0)
  player:setSkillUseHistory(skel.name, 0, Player.HistoryGame)
end)

return skel
